Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating*copies with missing values

    Hi Stata users,

    I have a dataset as shown in the example below

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(id c_avg v1) float v2 byte v3
    1 2 1 .7147 80
    1 4 1 .7147 80
    1 5 0 .7147 80
    2 1 1 .6579 67
    2 4 0 .6579 67
    3 5 1 .1249 57
    4 1 1 .0384 91
    4 2 1 .0384 91
    4 3 0 .0384 91
    4 4 1 .0384 91
    4 5 1 .0384 91
    5 1 1 .5049 69
    5 4 0 .5049 69
    5 5 0 .5049 69
    end
    For each id, there are instances where c_avg is missing and the idea is to create this instance with missing value for v1 BUT similar values for both v2 and v3 so that the final dataset can be

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(id c_avg v1) float v2 byte v3
    1 1 . .7147 80
    1 2 1 .7147 80
    1 3 . .7147 80
    1 4 1 .7147 80
    1 5 0 .7147 80
    2 1 1 .6579 67
    2 2 0 .6579 67
    2 3 0 .6579 67
    2 4 0 .6579 67
    2 5 0 .6579 67
    3 1 . .1249 57
    3 2 . .1249 57
    3 3 . .1249 57
    3 4 . .1249 57
    3 5 1 .1249 57
    4 1 1 .0384 91
    4 2 1 .0384 91
    4 3 0 .0384 91
    4 4 1 .0384 91
    4 5 1 .0384 91
    5 1 1 .5049 69
    5 2 0 .5049 69
    5 3 . .5049 69
    5 4 . .5049 69
    5 5 0 .5049 69
    end

    Thanks in advance!

  • #2
    maybe,
    Code:
    tsset id c_avg
    tsfill, full
    
    bysort id (v2): replace v2 = v2[1] if mi(v2)

    Comment


    • #3
      Thanks so much for the idea. I sincerely appreciate.

      Comment

      Working...
      X